#include "training.h"

//vector<string> TraningManager::_traningFileList;
//vector<string> TraningManager::_traningFolderList;
//string TraningManager::_rootFolder;
map<string, vector<string>> TraningManager::_allFiles;
TraningManager  *TraningManager::m_pInstance;

TraningManager::TraningManager()
{
	
}

TraningManager::~TraningManager()
{

}

vector<string> TraningManager::openFile(string& file)
{
	vector<string> fileWords = PdfManager::loadPdf(file);
	return fileWords;
}

int TraningManager::getTrainingCount()
{
	map<string, vector<string>>::iterator iter = _allFiles.begin();
	int cnt = 0;

	while(iter != _allFiles.end())
	{
		cnt = cnt + iter->second.size();
		++iter;
	}

	return cnt;
}

void TraningManager::setAllFiles(map<string, vector<string>>& allFiles)
{
	_allFiles = allFiles;
}

//
//void TraningManager::setTrainingFileList(vector<string>& fileList)
//{
//	_traningFileList = fileList;
//}
//
//void TraningManager::setTrainingFolderList(vector<string> &folderList)
//{
//
//	_traningFolderList = folderList;
//}
//
vector<string> TraningManager::getFolderName()
{
	vector<string> nameList;
	map<string, vector<string>>::iterator iter = _allFiles.begin();
	while(iter != _allFiles.end())
	{
		nameList.push_back(iter->first);
		++iter;
	}

	return nameList;
}

int TraningManager::getTraningClassificationsLen()
{
	return _allFiles.size();
}

int TraningManager::getTrainingCountOfClassification(string &classification)
{
	int ret=0;
	for (int i = 0; i < _allFiles[classification].size(); i++)
	{
		ret++;
	}

	return ret;
}

int TraningManager::getFileCountOfIDF(string& word)
{
	int ret = 0;
	map<string, vector<string>>::iterator mapIter;
	for(mapIter =  _allFiles.begin(); mapIter != _allFiles.end(); ++mapIter)
	{
		int size = mapIter->second.size();
		for(int i = 0; i < mapIter->second.size(); i++)
		{
			vector<string> wordList = openFile(mapIter->second.at(i));
			vector<string>::iterator vecIter = wordList.begin();
			for (;vecIter!=wordList.end(); ++vecIter)
			{
				if (*vecIter == word)
				{
					++ret;
				}
			}
		}
	}
	return ret;
}

int TraningManager::getTrainingCountOfKeyWord(string &classification,std::string &key)
{
		int ret = 0;
		
		vector<string> filePath = _allFiles[classification];

		for (int i = 0; i < filePath.size(); i++)
		{
			vector<string> wordList = openFile(filePath.at(i));
			vector<string>::iterator vecIter = wordList.begin();
			for (;vecIter!=wordList.end(); ++vecIter)
			{
				if (*vecIter == key)
				{
					++ret;
				}
			}
		}
		return ret;
}